package com.example.nick.bodyapplication

import java.util.*
import kotlin.math.roundToInt

fun printOk(value: Float, center: Float) {
    if (Math.abs(center - value) <= 0.3) {
        println("ok, center:$center, value:$value")
    } else {
        println("err, center:$center, value:$value")
    }
}

var weekDayArr = Array(size = 7, init = { Array(24, init = { 0 }) })

private fun dealItemCheck(r: Int, c: Int): Boolean {
    if (weekDayArr[c][r] == 1) {
        weekDayArr[c][r] = 0
        return true
    }

    var count = 24
    var left = r - 1
    var right = r + 1
    var canLeft = true
    var canRight = true
    var sum = 0
    while (--count > 0) {
        println("right:$right, canRight:$canRight")
        if (right < 24 && canRight) {
            if (weekDayArr[c][right] == 0) {
                canRight = false
            }
            right += 1
            sum += 1
        }
        println("left:$left, canLeft:$canLeft")
        if (left >= 0 && canLeft) {
            if (weekDayArr[c][left] == 0) {
                canLeft = false
            }
            left -= 1
            sum += 1
        }

        println("count$count, sum:$sum")
        if (sum >= 6) {
            return false
        }
    }
    weekDayArr[c][r] = 1
    return true
}



fun main() {
    for (i in 0..0) {
        println("pl 0 ...")
    }
//    val chanSet = mutableSetOf<Int>()
//    chanSet.add(1)
//    chanSet.add(3)
//    println("000 chanSet:$chanSet")
//    var chanSet2 = mutableSetOf<Int>()
//    chanSet2.addAll(chanSet)
//    chanSet2.add(4)
//    println("111 chanSet:$chanSet, chanSet2:$chanSet2")

//    var flag = 0b00000000
//    val flagHor = 0b00000001
//    val flagPsp = 0b00000010
//    flag = flag or flagHor
//    flag = flag or flagPsp
//    println("flag:$flag, flagHor:$flagHor, flagPsp:$flagPsp")
//    for (i in 0..3) {
//        weekDayArr[0][i] = 1
//    }
//
//    for (i in 6..10) {
//        weekDayArr[0][i] = 1
//    }
//
//    weekDayArr[0][12] = 1
//    val result = dealItemCheck(4, 0)
//    val result2 = dealItemCheck(11, 0)
//    println("result:$result, result2:$result2")
//    var column = 5
//    var row = 4
//    val alarmArrays = Array(size = column * row, init = { 1 })
//    val list0 = MutableList(3, { it * 2 })
//    val lista = listOf(1, 2, 3)
//    val sub = alarmArrays.filterIndexed { index, i ->
//        val r = index / column
//        val c = index % column
//        r >= 1 && r <= 2 && c >= 2 && c <= 3
//    }.map {
//        0
//    }
//    for (index in 0..alarmArrays.size) {
//        val r = index / column
//        val c = index % column
//        if (r >= 1 && r <= 2 && c >= 2 && c <= 3) {
//            alarmArrays[index] = 0
//        }
//    }
//    println("alarmArrays:${Arrays.toString(alarmArrays)}")
//    println("sub:$sub")

//    var listInt = listOf(1)
//    var sublist = listInt.subList(1, 1)
//    println(sublist)
//
//    var firF = 1.2f
//    var firF2 = 1.8f
//    var firF3 = 1.9f
//    var firF4 = 1.1f
//    var firI = firF.toInt()
//    var firCenter = firI + 0.5f
//    var firI2 = firF2.roundToInt()
////    println("$firF, $firI, $firF2, $firI2")
//    printOk(firF, firCenter)
//    printOk(firF2, firCenter)
//    printOk(firF3, firCenter)
//    printOk(firF4, firCenter)

//    val row = 2
//    val column = 3
//
//    val alarmArrays = Array(size = row, init = {IntArray(column, init = {1})})
//    alarmArrays.forEachIndexed { r, ints ->
//        ints.forEachIndexed { c, i ->
//            println("r:$r, c:$c, i:$i")
//        }
//    }
//
//    var a = 2L
//    var b = 200000L
//    var c = 26339000
//    var dd = c >= c.toDouble()
//    var ddd = c <= c.toDouble()
//    var fff = c / c.toDouble()
//    println("a:${a.toDouble()}, b:${b.toDouble()}, c:${c.toDouble()}, dd:$dd, ddd:$ddd, $fff")
//
//    var list = mutableListOf<String>("a")
//    val  list2 = mutableListOf<String>("b", "c", "d")
//    addData(list, list2)
//    println("$list")
}

fun addData(list: MutableList<String>, list2: MutableList<String>) {
    list2.forEach {
        list.add(it)
    }
}